package com.yixun.service.impl;

import com.yixun.entity.YxSysUser;
import com.yixun.mapper.UserMapper;
import com.yixun.service.UserService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @author lbx create by 2021/6/1 10:48
 * @apiNote UserServiceImpl
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Resource
    private BCryptPasswordEncoder bCryptPasswordEncoder;
    /**
     * @param map 用户信息封装
     * @return java.lang.Integer 用户ID
     * @apiNote createUser 添加用户
     */
    @Override
    public Integer createUser(HashMap<String, String> map) {
        map.put("password",bCryptPasswordEncoder.encode(map.get("password")));
        return userMapper.createUser(map);
    }
    
    @Override
    public List<YxSysUser> getUsersByPage(HashMap<String, Integer> map) {
        return userMapper.getUsersByPage(map);
    }
    
    @Override
    public Integer deactivateUser(HashMap<String, List<Long>> map) {
        return userMapper.deactivateUser(map);
    }
    
    @Override
    public Integer changePassword(HashMap<String, Object> map) {
        map.put("password",bCryptPasswordEncoder.encode((String)map.get("password")));
        return userMapper.changePassword(map);
    }
    
    @Override
    public Integer updateUser(HashMap<String, Object> map) {
        return userMapper.updateUser(map);
    }
}
